* show growth regressions with csr comparing estimation specifications

cd "~/Documents/econ/research/current/cognitive/estimation/dofiles"

use ../data/growth_panel, clear
xtset isonum year, delta(5)

label var lgdppw "Initial log GDP per worker"
label var PRI "Institutional quality (0-100)"
label var trade_open "Trade (\% of GDP)"
label var e0 "Life expectancy (years)"
label var yr_sch "Schooling (years)"
label var csr "Child survival (per 1000)"
label var asr "Adult survival (per 1000)"
label var csr_20 "Child survival, previous generation"

tab year if year>=1985, gen(yd) // create year dummies after 1985
drop yd1

local gmmlag 3
local lagvars "lgdppw PRI trade_open yr_sch asr"
local gvars "gPWT5 `lagvars' csr_20 yd*"
local gmm_rhs "gmm(`lagvars', laglimits(2 `gmmlag'))"
local xtabopts "robust twostep"
local star10 "starlevels(10 5 1) sigsymbols(+,*,**)"
local olsopts "se varlabel squarebrack noautosumm `star10'"
local outopts "`olsopts' drop(yd*)"
local adds `""Year effects", "yes" \ "N", "'

// -------------- OLS --------------
reg gPWT5 `lagvars' csr_2, robust
sum csr_20 if e(sample)
scalar csr_sd = r(sd)
sum trade_open if e(sample)
scalar trade_sd = r(sd)
qui tab country if e(sample)
mata: st_numscalar("e(N_g)", st_numscalar("r(r)"))
mata: st_numscalar("e(r2_t)", st_numscalar("e(r2)"))

outreg, `olsopts' ctitle("" "OLS") nodisplay ///
	addrow("Year effects", "no" \ "N", "`e(N)'" 	///
		\ "Countries", "`:display %3.0f e(N_g)'" 	///
		\ "\(R^2 \ ({Corr(\hat{y},y)}^2)\)", 			///
			"`:display %4.2f e(r2_t)'"				///
		\ "\% Growth from 1 s.d. $\Delta$ CSR", 	///
			"`:display %4.2f csr_sd*_b[csr_20]'"	///
		\ "\% Growth from 1 s.d. $\Delta$ Trade", 	///
			"`:display %4.2f trade_sd*_b[trade_open]'") 
outreg, store(csr_specs_kn) stat(b) varlabel 		///
	noautosumm keep(csr_20) 						///
	ctitle("" "OLS") nodisplay starloc(1) `star10'	///
	addrow("\% Growth from 1 s.d. $\Delta$ CSR", 	///
			"`:display %4.2f csr_sd*_b[csr_20]'"	///
		\ "\% Growth from 1 s.d. $\Delta$ Trade", 	///
			"`:display %4.2f trade_sd*_b[trade_open]'") 

// -------------- Fixed Effects --------------
xtreg `gvars', fe vce(cluster isonum)
xt_r2total
sum csr_20 if e(sample)
scalar csr_sd = r(sd)
sum trade_open if e(sample)
scalar trade_sd = r(sd)
outreg, `outopts' merge nodisplay 					///
	ctitle("" "Fixed" \ "" "Effects")  				///
	addrow("Year effects", "yes" \ "N", "`e(N)'" 	///
		\ "Countries", "`:display %3.0f e(N_g)'" 	///
		\ "\(R^2 \ ({Corr(\hat{y},y)}^2)\)", 		///
			"`:display %4.2f e(r2_t)'" 				///
		\ "\% Growth from 1 s.d. $\Delta$ CSR", 	///
			"`:display %4.2f csr_sd*_b[csr_20]'"	///
		\ "\% Growth from 1 s.d. $\Delta$ Trade", 	///
			"`:display %4.2f trade_sd*_b[trade_open]'") 
outreg, merge(csr_specs_kn) stat(b) varlabel 		///
	noautosumm keep(csr_20) nodisplay 				///
	starloc(1) `star10'								///
	ctitle("" "Fixed" \ "" "Effects")  				///
	addrow("\% Growth from 1 s.d. $\Delta$ CSR", 	///
			"`:display %4.2f csr_sd*_b[csr_20]'"	///
		\ "\% Growth from 1 s.d. $\Delta$ Trade", 	///
			"`:display %4.2f trade_sd*_b[trade_open]'") 

// -------------- Fixed Effects AR(1) --------------
xtregar `gvars', fe
xt_r2total
sum csr_20 if e(sample)
scalar csr_sd = r(sd)
sum trade_open if e(sample)
scalar trade_sd = r(sd)
outreg, `outopts' merge nodisplay 					///
	ctitle("" "Fixed Effects" \ "" "AR(1)")   		///
	addrow("Year effects", "yes" \ "N", "`e(N)'" 	///
		\ "Countries", "`:display %3.0f e(N_g)'" 	///
		\ "\(R^2 \ ({Corr(\hat{y},y)}^2)\)", 		///
			"`:display %4.2f e(r2_t)'" 				///
		\ "\% Growth from 1 s.d. $\Delta$ CSR", 	///
			"`:display %4.2f csr_sd*_b[csr_20]'"	///
		\ "\% Growth from 1 s.d. $\Delta$ Trade", 	///
			"`:display %4.2f trade_sd*_b[trade_open]'") 
outreg, merge(csr_specs_kn) stat(b) varlabel 		///
	noautosumm keep(csr_20) nodisplay				///
	starloc(1) `star10'								///
	ctitle("" "Fixed Effects" \ "" "AR(1)")  		///
	addrow("\% Growth from 1 s.d. $\Delta$ CSR", 	///
			"`:display %4.2f csr_sd*_b[csr_20]'"	///
		\ "\% Growth from 1 s.d. $\Delta$ Trade", 	///
			"`:display %4.2f trade_sd*_b[trade_open]'") 

// -------------- Arellano-Bond difference --------------
xtabond2 `gvars', `gmm_rhs' `xtabopts'	///
	noleveleq
xt_r2total
sum csr_20 if e(sample)
scalar csr_sd = r(sd)
sum trade_open if e(sample)
scalar trade_sd = r(sd)

outreg, `outopts' merge nodisplay 					///
	ctitle("" "Arellano" \ "" "Bond")  				///
	addrow("Year effects", "yes" \ "N", "`e(N)'" 	///
		\ "Countries", "`:display %3.0f e(N_g)'" 	///
		\ "\(R^2 \ ({Corr(\hat{y},y)}^2)\)", 		///
			"`:display %4.2f e(r2_t)'" 				///
		\ "\% Growth from 1 s.d. $\Delta$ CSR", 	///
			"`:display %4.2f csr_sd*_b[csr_20]'"	///
		\ "\% Growth from 1 s.d. $\Delta$ Trade", 	///
			"`:display %4.2f trade_sd*_b[trade_open]'") 
outreg, merge(csr_specs_kn) stat(b) varlabel 		///
	noautosumm keep(csr_20) nodisplay				///
	starloc(1) `star10'								///
	ctitle("" "Arellano" \ "" "Bond")				///
	addrow("\% Growth from 1 s.d. $\Delta$ CSR", 	///
			"`:display %4.2f csr_sd*_b[csr_20]'"	///
		\ "\% Growth from 1 s.d. $\Delta$ Trade", 	///
			"`:display %4.2f trade_sd*_b[trade_open]'") 

// Bundell-Bond system
xtabond2 `gvars', `gmm_rhs' `xtabopts'
di "xtabond2 `gvars', `gmm_rhs' `xtabopts'"
xt_r2total
sum csr_20 if e(sample)
scalar csr_sd = r(sd)
sum trade_open if e(sample)
scalar trade_sd = r(sd)
outreg using ../../draft/images/csr_specs, tex frag ///
	`outopts' merge									///
	ctitle("" "Blundell" \ "" "Bond") 				///
	addrow("Year effects", "yes" \ "N", "`e(N)'" 	///
		\ "Countries", "`:display %3.0f e(N_g)'" 	///
		\ "\(R^2 \ ({Corr(\hat{y},y)}^2)\)", 		///
			"`:display %4.2f e(r2_t)'" 				///
		\ "\% Growth from 1 s.d. $\Delta$ CSR", 	///
			"`:display %4.2f csr_sd*_b[csr_20]'"	///
		\ "\% Growth from 1 s.d. $\Delta$ Trade", 	///
			"`:display %4.2f trade_sd*_b[trade_open]'") 
outreg using ../../draft/images/csr_specs_kn, 		///
	tex frag merge(csr_specs_kn) 					///
	stat(b) varlabel noautosumm	keep(csr_20)		///
	starloc(1) `star10'								///
	ctitle("" "Blundell" \ "" "Bond")				///
	addrow("\% Growth from 1 s.d. $\Delta$ CSR", 	///
			"`:display %4.2f csr_sd*_b[csr_20]'"	///
		\ "\% Growth from 1 s.d. $\Delta$ Trade", 	///
			"`:display %4.2f trade_sd*_b[trade_open]'") 

